package com.jjzy.ioc;

import com.jjzy.pojo.Book;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Author:   wj
 * Date:     2020/2/10 20:49
 * Description: 属性注入
 */
public class PropertiesInto {
    /**
     * 通过构造方法的方式
     */
    @Test
    public void construction(){
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");
        //通过value
        Book book = (Book) ctx.getBean("book");
        //name方式
        Book book1 = (Book) ctx.getBean("book2");
        //通过set
        Book book2 = (Book) ctx.getBean("book3");
        //p名称空间
        Book book3 = (Book) ctx.getBean("book4");

        //测试属性是否注入
        System.out.println("book = " + book);
        System.out.println("book1 = " + book1);
        System.out.println("book2 = " + book2);
        System.out.println("book3 = " + book3);

    }
}
